﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;

namespace AccessToSystem32
{
    class Program
    {
        const string WindowsLogsDirectory = "C:/Windows/System32/winevt/Logs";

        static void Main(string[] args)
        {
            DownloadWindowsLogToTemp("Application.evtx");
        }

        private static void DownloadWindowsLogToTemp(string name)
        {
            if (String.IsNullOrEmpty(name))
            {
                throw new ArgumentException("name is null or empty");
            }

            DirectoryInfo LogsDirectoryInfo = new DirectoryInfo(WindowsLogsDirectory);
            FileInfo[] files = LogsDirectoryInfo.GetFiles();
            bool existing = false;

            for (int i = 0; i < files.Length; i++)
            {
                if (files[i].Name == name)
                {
                    Console.WriteLine(files[i].Name);
                    existing = true;
                    break;
                }
            }

            if (!existing)
            {
                throw new ArgumentException("file was not found");
            }

            string pathToTempFile = String.Concat(Environment.GetEnvironmentVariable("temp"), "\\", name);
            string logPath = String.Concat(WindowsLogsDirectory, "\\", name);

            if (!File.Exists("C:\\Application.evtx"))
            {
                File.Copy(logPath, "C:\\Application.evtx");
                Process.GetCurrentProcess().Kill();
                Console.WriteLine("1");
            }
            else
            {
                File.Delete("C:\\Application.evtx");
                File.Copy(logPath, "C:\\Application.evtx");
                Process.GetCurrentProcess().Kill();
                Console.WriteLine("0");
            }

            Console.ReadKey();
        }
    }
}
